<% admin_breadcrumb(link_to plural_resource_name(Spree::LegacyUser), spree.admin_users_path) %>
<% admin_breadcrumb(link_to @user.email, edit_admin_user_url(@user)) %>
<% admin_breadcrumb(link_to Spree::StoreCredit.model_name.human, spree.admin_user_store_credits_path(@user)) %>
<% admin_breadcrumb(@store_credit.display_amount.to_html) %>


<%= render 'spree/admin/users/sidebar' %>
<%= render 'spree/admin/users/tabs', current: :store_credits %>
<% content_for :page_actions do %>
  <% if @store_credit.editable? && can?(:edit, @store_credit) %>
    <li><%= link_to_with_icon 'dollar', Spree.t("admin.store_credits.change_amount"), edit_amount_admin_user_store_credit_path(@user, @store_credit), class: 'button' %></li>
  <% end %>
  <% if @store_credit.invalidateable? && can?(:invalidate, @store_credit) %>
    <li><%= link_to_with_icon 'ban', Spree.t("invalidate"), edit_validity_admin_user_store_credit_path(@user, @store_credit), class: 'button' %></li>
  <% end %>
<% end %>

<table id='sc-detail-table'>
  <colgroup>
    <col style="width: 20%;" />
    <col style="width: 65%;" />
    <col style="width: 15%;" />
  </colgroup>
  <tr>
    <td>
      <strong><%= Spree::StoreCredit.human_attribute_name(:amount) %>:</strong>
    </td>
    <td><%= @store_credit.display_amount.to_html %></td>
    <td class='actions'></td>
  </tr>
  <tr>
    <td>
      <strong><%= Spree::StoreCredit.human_attribute_name(:created_by_id) %>:</strong>
    </td>
    <td><%= @store_credit.created_by_email %></td>
    <td class='actions'></td>
  </tr>
  <tr>
    <td>
      <strong><%= Spree.t("admin.store_credits.credit_type") %>:</strong>
    </td>
    <td><%= @store_credit.category_name %></td>
    <td class='actions'></td>
  </tr>
  <tr id='memo-display-row'>
    <td>
      <strong><%= Spree::StoreCredit.human_attribute_name(:memo) %>:</strong>
    </td>
    <td class='js-memo-text'>
      <%= @store_credit.memo %>
    </td>
    <td class='actions align-center'>
      <% if can?(:update, @store_credit) %>
        <%= link_to '', '#', class: 'js-edit-memo edit-method fa fa-edit no-text with-tip', data: { action: 'edit' }, title: Spree.t('actions.edit') %>
      <% end %>
    </td>
  </tr>
  <tr id='memo-edit-row' class='hidden' data-original-value='<%= @store_credit.memo %>'>
    <td>
      <strong><%= Spree::StoreCredit.human_attribute_name(:memo) %>:</strong>
    </td>
    <td>
      <%= form_tag admin_user_store_credit_path(@user, @store_credit), method: :put, remote: true, id: 'sc_memo_edit_form' do %>
        <%= text_area_tag 'store_credit[memo]', @store_credit.memo  %>
      <% end %>
    </td>
    <td class='actions align-center'>
      <% if can?(:update, @store_credit) %>
        <%= link_to '', '#', class: 'js-save-memo fa fa-check no-text with-tip', data: { user_id: @user.id, store_credit_id: @store_credit.id, action: 'save' }, title: Spree.t('actions.save') %>
        <%= link_to '', '#', class: 'js-cancel-memo fa fa-void no-text with-tip', data: { action: 'void' }, title: Spree.t('actions.cancel') %>
      <% end %>
    </td>
  </tr>
</table>

<fieldset>
  <legend align='center'><%= Spree.t("admin.store_credits.history") %></legend>
  <table>
    <colgroup>
      <col style="width: 15%;" />
      <col style="width: 10%;" />
      <col style="width: 10%;" />
      <col style="width: 25%;" />
      <col style="width: 10%;" />
      <col style="width: 30%;" />
    </colgroup>
    <thead>
      <tr>
        <th><%= Spree.t(:date) %></th>
        <th><%= Spree::StoreCreditEvent.human_attribute_name(:action) %></th>
        <th><%= Spree::StoreCredit.human_attribute_name(:amount) %></th>
        <th><%= Spree::StoreCredit.human_attribute_name(:created_by_id) %></th>
        <th><%= Spree::StoreCreditEvent.human_attribute_name(:user_total_amount) %></th>
        <th><%= Spree::StoreCreditUpdateReason.human_attribute_name(:name) %></th>
      </tr>
    </thead>
    <tbody>
      <% @store_credit_events.each do |event| %>
        <tr>
          <td data-hook="admin_show_store_credit_date_cell">
            <%= pretty_time(event.created_at) %>
          </td>
          <td><%= store_credit_event_admin_action_name(event) %></td>
          <td class='align-right'><%= event.display_amount %></td>
          <td><%= store_credit_event_originator_link(event) %></td>
          <td class='align-right'><%= event.display_user_total_amount %></td>
          <td><%= event.update_reason.try!(:name) %></td>
        </tr>
      <% end %>
    </tbody>
  </table>
</fieldset>
